﻿/* Nibiru Studio Engine Version [1062] */
// Copyright (c) 2020-2023 Nibiru. All rights reserved.
#pragma once
#include "Apis/NComponent.h"
#include "Apis/NEngineApi.h"


ENGINE_NAMESPACE_BEGIN

#define SceneCalib_API DLLEXPORT

class EyeManager;
OBJECT_CLASS(SceneCalib)
class SceneCalib_API SceneCalib : public NComponent
{
	DECLARE_CLASS(SceneCalib, NComponent)
	DECLARE_RTTI
	ENABLE_REFLECTION
public:
	SceneCalib() = default;
	virtual ~SceneCalib() = default;
	
	virtual void Start() override;
	virtual void Update() override;
	virtual void OnDestroy() override;
	virtual void PostEditChangeProperty(std::string& propertyName) override;

	virtual void Serialize(Archive& ar) override;
	virtual void LateDeserialize(Archive& ar) override;

private:
    void updateEyeData();
    void doStop();
    // pupil
    // calibration
    void startCalibration();
    void startCalibrationPoint();
    void cancelCalibrationPoint();
    void completeCalibration();
    // calibration assist
    void prepareStartCalib(); // 准备校准点
    void showCalibView();
    void hideCalibView();
    void updateCalibPos(); // 校准点动画-移动
    void updateCalibScale(); // 校准点动画-缩放
    void getCalibPercent(); // 获取校准点进度
    // switch scene
    void switchToTarget();
    void switchToCapture();


private:
    EyeManager *m_pEyeManager = nullptr;
    NLabelPtr m_textMessage;
    // pupil view
    NActorPtr m_panelLeftPupil; // 左眼瞳孔actor
    NActorPtr m_panelRightPupil; // 右眼瞳孔actor
    NActorPtr m_imgLeftPupil; // 左眼瞳孔image
    NActorPtr m_imgRightPupil; // 右眼瞳孔image
    // pupil param
    float m_panelPupilWidth = 1.0f;
    float m_panelPupilHeight = 1.0f;
    int m_pupilValidCount = -1;
    int m_caliTotalNum = 7;
    // calibration view
    NActorPtr m_panelCalib; // 校准面板
    NActorPtr m_calibPoint; // 校准点
    vector<NActorPtr> m_calibPointList;

    // calibration param


























    int m_calibPointCount = 9;
    float m_panelCalibWidth = 1.0f;
    float m_panelCalibHeight = 1.0f;
    int m_calibIndex = 0;
    float m_calibLastX = 0;
    float m_calibLastY = 0;
    float m_calibPosDX = 0;
    float m_calibPosDY = 0;
    float m_calibPosRatio = 0;
    float m_offsetY = 0.21;
    bool m_calibPosValid = false;
    float m_calibScale = 1.0f;
    bool m_calibScaleValid = false;
    bool m_calibPercentValid = false;
    int m_calibPercentCount = 10;

};
DECLARE_PTR(SceneCalib)
ENGINE_NAMESPACE_END
